<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
		<head>
			<!-- template designed by Marco Von Ballmoos -->
			<title>Docs For Class Services_JSON</title>
			<link rel="stylesheet" href="../media/stylesheet.css" />
			<meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'/>
		</head>
		<body>
			<div class="page-body">			
<h2 class="class-name">Class Services_JSON</h2>

<a name="sec-description"></a>
<div class="info-box">
	<div class="info-box-title">Description</div>
	<div class="nav-bar">
					<span class="disabled">Description</span> |
															<a href="#sec-method-summary">Methods</a> (<a href="#sec-methods">details</a>)
						
			</div>
	<div class="info-box-body">
		<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">Converts to and from JSON format.</p>
<p class="description"><p>Brief example of use:</p><p><pre><code><pre><br />1     <span class="src-comm">// create a new instance of Services_JSON</span><br />2      <span class="src-var">$json</span> = <span class="src-key">new</span> <a href="../Services_JSON/Services_JSON.html#methodServices_JSON">Services_JSON</a><span class="src-sym">(</span><span class="src-sym">)</span>;<br />3     <br />4      <span class="src-comm">// convert a complexe value to JSON notation, and send it to the browser</span><br />5      <span class="src-var">$value</span> = <span class="src-key">array</span><span class="src-sym">(</span><span class="src-str">'foo'</span><span class="src-sym">,</span> <span class="src-str">'bar'</span><span class="src-sym">,</span> <span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">1</span><span class="src-sym">,</span> <span class="src-num">2</span><span class="src-sym">,</span> <span class="src-str">'baz'</span><span class="src-sym">)</span><span class="src-sym">,</span> <span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">3</span><span class="src-sym">,</span> <span class="src-key">array</span><span class="src-sym">(</span><span class="src-num">4</span><span class="src-sym">)</span><span class="src-sym">)</span><span class="src-sym">)</span>;<br />6      <span class="src-var">$output</span> = <span class="src-var">$json</span><span class="src-sym">-&gt;</span><a href="../Services_JSON/Services_JSON.html#methodencode">encode</a><span class="src-sym">(</span><span class="src-var">$value</span><span class="src-sym">)</span>;<br />7     <br />8      print<span class="src-sym">(</span><span class="src-var">$output</span><span class="src-sym">)</span>;<br />9      <span class="src-comm">// prints: [&quot;foo&quot;,&quot;bar&quot;,[1,2,&quot;baz&quot;],[3,[4]]]</span><br />10    <br />11     <span class="src-comm">// accept incoming POST data, assumed to be in JSON notation</span><br />12     <span class="src-var">$input</span> = <a href="http://www.php.net/file_get_contents">file_get_contents</a><span class="src-sym">(</span><span class="src-str">'php://input'</span><span class="src-sym">,</span> <span class="src-num">1000000</span><span class="src-sym">)</span>;<br />13     <span class="src-var">$value</span> = <span class="src-var">$json</span><span class="src-sym">-&gt;</span><a href="../Services_JSON/Services_JSON.html#methoddecode">decode</a><span class="src-sym">(</span><span class="src-var">$input</span><span class="src-sym">)</span>;</pre></code></pre></p></p>
		<p class="notes">
			Located in <a class="field" href="_JSON_php.html">/JSON.php</a> (line <span class="field">115</span>)
		</p>
		
				
		<pre></pre>
	
			</div>
</div>



	<a name="sec-method-summary"></a>
	<div class="info-box">
		<div class="info-box-title">Method Summary</span></div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
									<span class="disabled">Methods</span> (<a href="#sec-methods">details</a>)
		</div>
		<div class="info-box-body">			
			<div class="method-summary">
								
				<div class="method-definition">
											<span class="method-result">Services_JSON</span>
										<a href="#Services_JSON" title="details" class="method-name">Services_JSON</a>
											(<span class="var-type">int</span>&nbsp;<span class="var-name">$use</span>)
									</div>
								
				<div class="method-definition">
											<span class="method-result">mixed</span>
										<a href="#decode" title="details" class="method-name">decode</a>
											(<span class="var-type">string</span>&nbsp;<span class="var-name">$str</span>)
									</div>
								
				<div class="method-definition">
											<span class="method-result">mixed</span>
										<a href="#encode" title="details" class="method-name">encode</a>
											(<span class="var-type">mixed</span>&nbsp;<span class="var-name">$var</span>)
									</div>
								
				<div class="method-definition">
											<span class="method-result">void</span>
										<a href="#isError" title="details" class="method-name">isError</a>
											(<span class="var-type">mixed</span>&nbsp;<span class="var-name">$data</span>, [<span class="var-type">mixed</span>&nbsp;<span class="var-name">$code</span> = <span class="var-default">null</span>])
									</div>
							</div>
		</div>
	</div>		

	
	<a name="sec-methods"></a>
	<div class="info-box">
		<div class="info-box-title">Methods</div>
		<div class="nav-bar">
			<a href="#sec-description">Description</a> |
													<a href="#sec-method-summary">Methods</a> (<span class="disabled">details</span>)
						
		</div>
		<div class="info-box-body">
			<A NAME='method_detail'></A>
<a name="methodServices_JSON" id="Services_JSON"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">Constructor Services_JSON</span> (line <span class="line-number">133</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">constructs a new JSON instance</p>
	
	<div class="method-signature">
		<span class="method-result">Services_JSON</span>
		<span class="method-name">
			Services_JSON
		</span>
					(<span class="var-type">int</span>&nbsp;<span class="var-name">$use</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">int</span>
				<span class="var-name">$use</span><span class="var-description">: <p>object behavior flags; combine with boolean-OR</p><p>possible values: <ul><li>SERVICES_JSON_LOOSE_TYPE:  loose typing.
                                   &quot;{...}&quot; syntax creates associative arrays
                                   instead of objects in decode().</li><li>SERVICES_JSON_SUPPRESS_ERRORS:  error suppression.
                                   Values which can't be encoded (e.g. resources)
                                   appear as NULL instead of throwing errors.
                                   By default, a deeply-nested resource will
                                   bubble up with an error, so all return values
                                   from encode() should be checked with isError()</li></ul></p></span>			</li>
				</ul>
		
		
	</div>
<a name="methoddecode" id="decode"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">decode</span> (line <span class="line-number">484</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">decodes a JSON string into appropriate variable</p>
	<ul class="tags">
				<li><span class="field">return:</span> number, boolean, string, array, or object                    corresponding to given JSON input string.                    See argument 1 to Services_JSON() above for object-output behavior.                    Note that decode() always returns strings                    in ASCII or UTF-8 format!</li>
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">mixed</span>
		<span class="method-name">
			decode
		</span>
					(<span class="var-type">string</span>&nbsp;<span class="var-name">$str</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">string</span>
				<span class="var-name">$str</span><span class="var-description">: JSON-formatted string</span>			</li>
				</ul>
		
		
	</div>
<a name="methodencode" id="encode"><!-- --></a>
<div class="evenrow">
	
	<div class="method-header">
		<span class="method-title">encode</span> (line <span class="line-number">237</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
<p class="short-description">encodes an arbitrary variable into JSON format</p>
	<ul class="tags">
				<li><span class="field">return:</span> JSON string representation of input var or an error if a problem occurs</li>
				<li><span class="field">access:</span> public</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">mixed</span>
		<span class="method-name">
			encode
		</span>
					(<span class="var-type">mixed</span>&nbsp;<span class="var-name">$var</span>)
			</div>
	
			<ul class="parameters">
					<li>
				<span class="var-type">mixed</span>
				<span class="var-name">$var</span><span class="var-description">: any number, boolean, string, array, or object to be encoded.                            see argument 1 to Services_JSON() above for array-parsing behavior.                            if var is a strng, note that encode() always expects it                            to be in ASCII or UTF-8 format!</span>			</li>
				</ul>
		
		
	</div>
<a name="methodisError" id="isError"><!-- --></a>
<div class="oddrow">
	
	<div class="method-header">
		<span class="method-title">isError</span> (line <span class="line-number">766</span>)
	</div> 
	
	<!-- ========== Info from phpDoc block ========= -->
	<ul class="tags">
				<li><span class="field">todo:</span> Ultimately, this should just call PEAR::isError()</li>
			</ul>
	
	<div class="method-signature">
		<span class="method-result">void</span>
		<span class="method-name">
			isError
		</span>
					(<span class="var-type">mixed</span>&nbsp;<span class="var-name">$data</span>, [<span class="var-type">mixed</span>&nbsp;<span class="var-name">$code</span> = <span class="var-default">null</span>])
			</div>
	
		
		
	</div>
						
		</div>
	</div>
	
	<p class="notes" id="credit">
		Documentation generated on Tue, 27 Jun 2006 22:54:25 -0700 by <a href="http://www.phpdoc.org" target="_blank">phpDocumentor 1.2.3</a>
	</p>
	</div></body>
</html>